define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            Table.api.init({
                extend: {
                    index_url: 'scanwork/qrc/index' + location.search,
                    del_url: 'scanwork/qrc/del',
                    table: 'qrc',
                }
            });
            var table = $("#table");
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: 'ID'},
                        {field: 'order_no', title: '订单号'},
                        {field: 'product_name', title: '产品名称'},
                        {field: 'model_name', title: '型号名称'},
                        {field: 'process_name', title: '工序名称'},
                        {field: 'user_name', title: '员工'},
                        {field: 'quantity', title: '任务数量'},
                        {field: 'qr_image', title: '二维码', formatter: function(value) {
                            return value ? '<img src="'+value+'" style="width:60px;height:60px;">' : '-';
                        }},
                        {field: 'scan_count', title: '扫码次数'},
                        {field: 'status', title: '状态', formatter: Table.api.formatter.status},
                        {field: 'createtime', title: '生成时间', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: '操作', table: table, events: {
                            'click .btn-print-qrc': function (e, value, row, index) {
                                var img = row.qr_image;
                                var win = window.open('');
                                win.document.write('<img src="' + img + '" style="width:300px;height:300px;">');
                                win.print();
                            }
                        }, formatter: function(value, row, index) {
                            var html = '';
                            if (row.qr_image) {
                                html += '<a href="' + row.qr_image + '" class="btn btn-xs btn-info" target="_blank"><i class="fa fa-eye"></i> 查看</a> ';
                                html += '<a href="' + row.qr_image + '" class="btn btn-xs btn-success" download><i class="fa fa-download"></i> 下载</a> ';
                                html += '<a href="javascript:;" class="btn btn-xs btn-warning btn-print-qrc" data-img="' + row.qr_image + '"><i class="fa fa-print"></i> 打印</a> ';
                            }
                            return html;
                        }}
                    ]
                ]
            });
            Table.api.bindevent(table);
        }
    };
    return Controller;
}); 